package com.google.code.netcheckin.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.google.code.netcheckin.aprs.Station;
import com.google.code.netcheckin.util.StationCallCollator;

/**
  * An implementation of Comparator that collates two station based
  * on the suffices of their call signs (APRS object names).
  * @author Dick Repasky
  *
*/

public class StationCallSuffixCollator extends StationCallCollator {

	protected Pattern digitPattern;

	public StationCallSuffixCollator() {
		super();
		digitPattern = Pattern.compile("\\d");
	}

	protected String getCallsign(Station stn) {
		return swapPrefixSuffix(super.getCallsign(stn));
	}

	protected String swapPrefixSuffix(String callsign) {
		Matcher m = digitPattern.matcher(callsign);
		if (m.find()) {
			int start = m.start() + 1;
			int end = m.end();
			callsign = callsign.substring(end) + " " + 
					callsign.substring(0, start);
		}
		return callsign;
	}

}
